package fr.utbm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import fr.utbm.Sensor.SensorType;

public class Patient extends User implements Comparable<Patient>, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	static int id_counter = 0;
	
	private int id;
	
	private String name;
	
	private List<Sensor> sensors;

	public Patient(String name) {
		super();
		this.name = name;
		this.id = id_counter++;
		sensors = new ArrayList<Sensor>();
	}

	
	/**
	 * Create a new Patient from database
	 * @param id
	 * @param username
	 * @param password
	 * @param type
	 * @param profil_nom
	 * @param profil_prenom
	 * @param profil_age
	 * @param profil_taille
	 * @param profil_photo_url
	 */
	public Patient(int id, String username, String password, int type,
			String profil_nom, String profil_prenom, int profil_age,
			double profil_taille, String profil_photo_url) {
		
		super(id, username, password, type, profil_nom, profil_prenom, profil_age,
				profil_taille, profil_photo_url);
		
		sensors = new ArrayList<Sensor>();
		
	}

	public String getName() {
		return super.getProfil_prenom() + " " + super.getProfil_nom();
	}

	/*public void setName(String name) {
		this.name = name;
	}*/

	/*public int getId() {
		return id;
	}*/
	
	@Override
	public int compareTo(Patient other) {
		//return name.compareTo(other.name);
		return getUsername().compareTo(other.getUsername());
	}
	
	public List<Sensor> getSensors() {
		return sensors;
	}

	public Sensor getSensor(int sensorID) {
		for (Sensor s : sensors) {
			if (s.getType().getID() == sensorID) {
				return s;
			}
		}
		return null;
	}
	
	public void addSensor(Sensor sensor) {
		sensors.add(sensor);
	}
}
